<template>
  <div>
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="modelFormHandle()" type="primary" icon="plus">新增</a-button>
      <a-button
          @click="batchDeleteHandle"
          v-if="selectedRowKeys.length > 0"
          ghost
          type="primary"
          icon="delete">批量删除
      </a-button>
    </div>

    <!-- table区域-begin -->
    <div>

      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i>已选择&nbsp;<a style="font-weight: 600">{{
          selectedRowKeys.length
        }}</a>项&nbsp;&nbsp;
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
          rowKey="id"
          :columns="columns"
          size="middle"
          :pagination="false"
          :dataSource="dataList"
          :loading="loading"
          :expandedRowKeys="selectedRowKeys"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
          @expandedRowsChange="tableChangeHandle">

          <span slot="action" slot-scope="text, record">
            <a @click="modelFormHandle(record)">编辑</a>

            <a-divider type="vertical" />

            <a-popconfirm title="确定删除吗?" @confirm="() => deleteHandle(record.id)">
              <a>删除</a>
            </a-popconfirm>
          </span>
      </a-table>

    </div>
    <!-- table区域-end -->

    <model-form ref="modelForm" v-if="modelFormVisible" @ok="modalFormOk"></model-form>
  </div>
</template>

<script>
import listMixin from '@/mixins/list-mixin'
import modelForm from './form'

export default {
  name: "list",
  mixins: [listMixin],
  components: {
    modelForm,
  },
  data () {
    return {
      disableMixinCreated: true,
      columns: [
        {
          title: '#',
          dataIndex: '',
          key:'rowIndex',
          width:60,
          align:"center",
          customRender:function (t,r,index) {
            return parseInt(index)+1;
          }
        },
        {
          title: '权重id',
          align: "center",
          dataIndex: 'appraiseTiesId',
        },
        {
          title: '权重关系',
          align: "center",
          dataIndex: 'appraiseTies',
        },
        {
          title: '操作',
          align: "center",
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
        }
      ],
      url: {
        list: '/weight/getList'
      }
    }
  },
  methods: {
    // 新增 / 修改
    modelFormHandle (record) {
      this.modelFormVisible = true
      this.$nextTick(() => {
        this.$refs.modelForm.init(record)
      })
    },
  }
}
</script>

<style scoped>

</style>
